package com.gdit.revenue.controller;


import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.gdit.revenue.base.result.Results;
import com.gdit.revenue.model.Expenditure;
import com.gdit.revenue.model.User;
import com.gdit.revenue.service.ExpenditureService;
import com.gdit.revenue.service.Impl.ExpenditureServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/expenditure")
public class ExpenditureController {
    //这个就开始AOP面向切面编程
    private static final Log log = LogFactory.getLog(ExpenditureController.class);
    @Autowired
    ExpenditureService expenditureServiceImpl;
    @RequestMapping("/expenditurelist")
    @ResponseBody   //解析Json数据
    public Results userlist(int page, int limit){
        log.warn("用户调用了/expenditure/expenditurelist");    //日志
        int start = (page-1)*limit;     //第几个数据开始展示
        return expenditureServiceImpl.getAllExpenditures(start,limit);
    }

    @RequestMapping("/addexpenditure")
    public String addexpenditure(){
        return "/expenditure/addexpenditure";
    }



    @RequestMapping("/delete")
    @ResponseBody
    public Results delete(int orderid){
        return expenditureServiceImpl.delete(orderid);
    }
    @PostMapping("/addExpenditure")
    @ResponseBody
    public int addUser(@RequestBody Expenditure expenditure){
        expenditureServiceImpl.addExpenditure(expenditure);
        return 0;
    }





}
